{{include file="public/header" /}}

<!-- right content start  -->
<div class="content-right">
	<div class="content">
		<!-- form start -->
		<form class="am-form form-validation" action="{{:MyUrl('admin/payment/save')}}" method="POST" request-type="ajax-url" request-value="{{:MyUrl('admin/payment/index')}}" enctype="multipart/form-data">
			<legend>
				<span class="am-text-default">支付方式{{if empty($data['id'])}}添加{{else /}}编辑{{/if}}</span>
				<a href="{{:MyUrl('admin/payment/index')}}" class="am-fr am-text-sm am-margin-top-sm am-icon-mail-reply"> 返回</a>
			</legend>
			{{if empty($data)}}
					{{include file="public/not_data" /}}
			{{else /}}
				<div class="am-form-group">
					<label>名称</label>
					<input type="text" name="name" placeholder="名称" minlength="2" maxlength="60" data-validation-message="名称格式 2~30 个字符" class="am-radius" {{if !empty($data)}} value="{{$data.name}}"{{/if}} required />
				</div>
				<div class="am-form-group">
					<label>适用终端</label>
				    <select name="apply_terminal" class="am-radius chosen-select" multiple="multiple" minchecked="1" data-placeholder="可选择..." data-validation-message="至少选择一个适用终端" required>
						{{foreach $common_platform_type as $v}}
							{{if isset($data) and isset($data['apply_terminal_old']) and is_array($data['apply_terminal_old']) and in_array($v['value'], $data['apply_terminal_old'])}}
								<option value="{{$v.value}}" {{if isset($data['apply_terminal']) and in_array($v['value'], $data['apply_terminal'])}}selected{{/if}}>{{$v.name}}</option>
							{{/if}}
						{{/foreach}}
					</select>
				</div>

				<div class="am-form-group am-form-file">
					<label class="block">LOGO</label>
					<ul class="plug-file-upload-view logo-images-view" data-form-name="logo" data-max-number="1" data-dialog-type="images">
						{{if !empty($data['logo'])}}
							<li>
								<input type="text" name="logo" value="{{$data.logo}}" />
								<img src="{{$data.logo}}" />
								<i>×</i>
							</li>
						{{/if}}
					</ul>
					<div class="plug-file-upload-submit" data-view-tag="ul.logo-images-view">+上传图片</div>
				</div>

				<!-- plugins config start -->
				{{if !empty($data['element'])}}
					<div class="am-alert am-alert-secondary">
						<label class="am-text-sm am-text-warning">该区域为插件配置填写项，请按照插件文档填写相应的值</label>
						{{foreach $data.element as $element}}
							<div class="am-form-group">
								{{if !empty($element['title'])}}
									<label class="block">{{$element.title}}{{if !empty($element['desc'])}}<span class="am-form-group-label-tips">{{$element.desc}}</span>{{/if}}</label>
								{{/if}}
								{{switch element.element}}
									{{case input}}
										{{if in_array($element['type'], ['radio', 'checkbox']) and !empty($element['element_data']) and is_array($element['element_data'])}}
											{{foreach $element.element_data as $element_data_key=>$element_data}}
												<label class="{{if isset($element['is_block']) and $element['is_block'] eq 1}}am-{{$element.type}}{{else /}}am-{{$element.type}}-inline{{/if}}">
													<input
														type="{{$element.type}}"
														name="plugins_{{$element.name}}"
														value="{{$element_data.value}}"

														{{if isset($data['config'][$element['name']]) and in_array($element_data['value'], explode(',', $data['config'][$element['name']]))}} checked{{/if}}

														{{if isset($element['minchecked']) and $element['type'] eq 'checkbox'}} minchecked="{{$element.minchecked}}"{{/if}}

														{{if isset($element['maxchecked']) and $element['type'] eq 'checkbox'}} maxchecked="{{$element.maxchecked}}"{{/if}}

														{{if isset($element['message'])}} data-validation-message="{{$element.message}}"{{/if}}

														{{if $element_data_key eq 0 and isset($element['is_required']) and $element['is_required'] eq 1}}required{{/if}}
														data-am-ucheck />
														{{$element_data.name}}
												</label>
											{{/foreach}}
										{{else /}}
											<input
												class="am-radius"
												type="{{$element.type}}"
												name="plugins_{{$element.name}}"
												value="{{if isset($data['config'][$element['name']])}}{{$data['config'][$element['name']]}}{{else /}}{{if isset($element['default'])}}{{$element.default}}{{/if}}{{/if}}"

												{{if isset($element['placeholder'])}} placeholder="{{$element.placeholder}}"{{/if}}

												{{if isset($element['message'])}} data-validation-message="{{$element.message}}"{{/if}}

												{{if isset($element['is_required']) and $element['is_required'] eq 1}} required{{/if}}
												/>
										{{/if}}
									{{/case}}
									{{case select}}
										{{if !empty($element['element_data']) and is_array($element['element_data'])}}
											<select
												class="chosen-select am-radius"
												name="plugins_{{$element.name}}"

												{{if isset($element['message'])}} data-validation-message="{{$element.message}}"{{/if}}

												{{if !empty($element['placeholder'])}} data-placeholder="{{$element.placeholder}}"{{/if}}

												{{if isset($element['is_multiple']) and $element['is_multiple'] eq 1}}
													multiple
													{{if isset($element['minchecked'])}} minchecked="{{$element.minchecked}}"{{/if}}
													{{if isset($element['maxchecked'])}} maxchecked="{{$element.maxchecked}}"{{/if}}
												{{/if}}

												{{if isset($element['is_required']) and $element['is_required'] eq 1}}required{{/if}}
											>
											{{if !isset($element['is_multiple']) or $element['is_multiple'] neq 1}}
												{{if !empty($element['placeholder'])}}
													<option value="">{{$element.placeholder}}</option>
												{{/if}}
											{{/if}}
												{{foreach $element.element_data as $element_data_key=>$element_data}}
													<option
														value="{{$element_data.value}}"
														{{if isset($data['config'][$element['name']]) and in_array($element_data['value'], explode(',', $data['config'][$element['name']]))}}selected{{/if}}
														>{{$element_data.name}}</option>
												{{/foreach}}
											</select>
										{{/if}}
									{{/case}}
									{{case textarea}}
										<textarea
											class="am-radius"
											name="plugins_{{$element.name}}"

											{{if isset($element['rows'])}} rows="{{$element.rows}}"{{/if}}

											{{if isset($element['placeholder'])}} placeholder="{{$element.placeholder}}"{{/if}}

											{{if isset($element['is_required']) and $element['is_required'] eq 1}}
												{{if isset($element['minlength'])}} minlength="{{$element.minlength}}"{{/if}}
												{{if isset($element['maxlength'])}} maxlength="{{$element.maxlength}}"{{/if}}
												required
											{{/if}}
										>{{if isset($data['config'][$element['name']])}}{{$data['config'][$element['name']]}}{{else /}}{{if isset($element['default'])}}{{$element.default}}{{/if}}{{/if}}</textarea>
									{{/case}}
									{{case message}}
										<div class="am-alert am-alert-danger" data-am-alert>
											{{$element.message|raw}}
										</div>
									{{/case}}
								{{/switch}}
							</div>
						{{/foreach}}
					</div>
				{{/if}}
				<!-- plugins config end -->

				<div class="am-form-group">
					<label>顺序</label>
					<input type="number" placeholder="顺序" name="sort" min="0" max="255" data-validation-message="顺序 0~255 之间的数值" class="am-radius" value="{{if isset($data['sort'])}}{{$data.sort}}{{else /}}0{{/if}}" required />
				</div>

				<div class="am-form-group">
				    <label class="block">用户开放</label>
				    <input name="is_open_user" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_open_user']) and $data['is_open_user'] eq 1) or !isset($data['is_open_user'])}}checked="true"{{/if}} />
				</div>

				<div class="am-form-group">
				    <label class="block">是否启用</label>
				    <input name="is_enable" value="1" type="checkbox" data-off-text="否" data-on-text="是" data-size="xs" data-on-color="success" data-off-color="default" data-handle-width="50" data-am-switch {{if (isset($data['is_enable']) and $data['is_enable'] eq 1) or !isset($data['is_enable'])}}checked="true"{{/if}} />
				</div>
				<div class="am-form-group am-form-group-refreshing am-margin-top-lg am-padding-left-0">
					<input type="hidden" name="id" {{if !empty($data)}} value="{{$data.id}}"{{/if}} />
					<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block" data-am-loading="{loadingText:'处理中...'}">保存</button>
				</div>
			{{/if}}
		</form>
        <!-- form end -->
	</div>
</div>
<!-- right content end  -->
		
<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->
<script>
$('.select-maxchecked').on('checkedOverflow.selected.amui', function() {
  Prompt('最多选择' + this.getAttribute('maxchecked') + '项');
});
</script>